using System;
using System.Drawing;
using System.Windows.Forms;

public class ImageButton:Control
{
	private Image UpImg;
	private Image DownImg;
	private bool pressed;
	private bool release;

	public ImageButton (bool autorelease):base()
	{
		release = autorelease;
		this.pressed = false;
	}
	public bool Pressed
	{
		get{return pressed;}
		set
		{
			this.pressed = value;
			Invalidate();
		}
	}
	public Image UpImage
	{
		get{return this.UpImg;}
		set{this.UpImg = value;}
	}
	public Image DownImage
	{
		get{return this.DownImg;}
		set{this.DownImg = value;}
	}

	protected override void OnMouseDown(MouseEventArgs e)
	{
		this.pressed = !this.pressed;
		base.OnMouseDown (e);
		this.Invalidate();
	}
	protected override void OnMouseUp(MouseEventArgs e)
	{
		if (release)
		{
			this.pressed = false;
			this.Invalidate();
		}
		base.OnMouseUp (e);
	}

	protected override void OnPaintBackground(PaintEventArgs e)
	{
		if (this.pressed==true && this.DownImg!=null)
			e.Graphics.DrawImage(this.DownImg,0,0);
		else
			e.Graphics.DrawImage(this.UpImg,0,0);
	}
}

 